#!/bin/bash
#

##石头剪刀布游戏

arry=("石头" "剪刀" "布")

menu="
0.石头
1.剪刀
2.布
请选择您的拳法[0|1|2]："

read -p "$menu" num

case $num in
    0|1|2)
	pnum=$num
	;;
    *)
	echo "请输入数字0或1或2,0代表石头,1代表剪刀,2代表布"
	exit 290
	;;
esac
	
cnum=$RANDOM%3

#echo ${arry[$cnum]}
#echo ${arry[$pnum]}

declare -A win_arry
declare -A pingju_arry
win_arry=(["石头"]="剪刀" ["剪刀"]="布" ["布"]="石头")
pingju_arry=([石头]=石头 [剪刀]=剪刀 [布]=布)

i=${arry[$pnum]}
if [ "${win_arry[$i]}" == "${arry[$cnum]}" ]; then
    echo "恭喜您，您获胜了，您的拳法是：${arry[$pnum]}，机器的拳法是：${arry[$cnum]}"
elif [ ${pingju_arry[$i]} == ${arry[$cnum]} ];then
    echo "啊，平局了，您的拳法是：${arry[$pnum]}，机器的拳法是：${arry[$cnum]}"
else 
    echo "哟，你输了，你的拳法是：${arry[$pnum]}，机器的拳法是：${arry[$cnum]}"
fi
